package com.maxuxu.scihome.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.maxuxu.scihome.mapper.JobMapper;
import com.maxuxu.scihome.pojo.Job;
import com.maxuxu.scihome.pojo.Pages;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @className: JobService
 * @author: Maxuxu
 * @date: 2022/7/4 22:36
 * @description: 工作的服务类
 */
@Service
public class JobService {
    @Autowired
    Job job;
    @Autowired
    JobMapper jobMapper;

    @Autowired
    Pages pages;

    public String insertJob(Job job){
        jobMapper.insert(job);
        return "插入成功";
    }
    public Pages selectPage(long current, long size){
        Page<Job> Page =  jobMapper.selectPage(new Page<>(current, size), null);
        List<Job> records = Page.getRecords();
        long total = Page.getTotal();
        long pages = Page.getPages();
        long current1 = Page.getCurrent();
        long size1 = Page.getSize();
        this.pages.setPages(pages);
        this.pages.setCurrent(current1);
        this.pages.setSize(size1);
        this.pages.setTotal(total);
        this.pages.setRecords(records);
        return this.pages;
    }


    public Job selectByAny(Job Job){
        QueryWrapper<Job> wrapper = new QueryWrapper<>();
        wrapper.eq("name", Job.getName());
        Job Job1 =  jobMapper.selectOne(wrapper);
        return Job1;
    }

    public void deletJob(List<Integer> list){
         jobMapper.deleteBatchIds(list);
    }

    public void updateJob(String oldname,Job Job){
        UpdateWrapper<Job> wrapper = new UpdateWrapper<>();
        wrapper.eq("name", oldname);
         jobMapper.update(Job, wrapper);

    }
}
